<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="description" content="">
	<meta name="keywords" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<title>昆钢水泥集团</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="icon" type="image/png" href="i/favicon.png">
	<meta name="mobile-web-app-capable" content="yes">
	<link rel="icon" sizes="192x192" href="i/app-icon72x72@2x.png">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-title" content="Amaze UI" />
	<link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">
	<meta name="msapplication-TileImage" content="i/app-icon72x72@2x.png">
	<meta name="msapplication-TileColor" content="#0e90d2">
	<link rel="stylesheet" href="css/amazeui.min.css">
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/amazeui.min.js"></script>
		<script src="js/mui.js" ></script>
   <script src="myjs/common.js" ></script>
		<script src="myjs/editInfo.js"></script>
		<script src="js/sweetalert/dist/sweetalert-dev.js"></script>
		<link rel="stylesheet" href="js/sweetalert/dist/sweetalert.css">
	</head>

	<body style="background: url(img/login-bg.jpg) center no-repeat; overflow: show;">
		<style type="text/css">
			.am-form {
				font-size: 15px;
			}
			.am-icon-angle-left{
				color: white;
			}
		</style>

		<!--1-->
	 <header data-am-widget="header"
          class="am-header am-header-default ">
         <a href="user.html">
          	<span class="am-icon-angle-left am-left am-icon-md am-fl"></span>
         </a> 
		<h1 class="am-header-title">修改注册</h1>
		<div class="am-header-right am-header-nav">
          <a href="user.html">
        <span class="am-icon-user am-icon-sm"></span>
      </a>         
      </div>
	</header>
	<!--1-->

		<div class="am-g am-none" style="margin: 8px 0px; ">
			<span class="am-margin-left-xs">所选工厂:</span>
			<span id="selecteds"></span>
		</div>

		<div class="am-g">
			<form action="" class="am-form">
				<input type="hidden"  id="wx_id" value="" />
				<fieldset>
					<div class="am-form-group">
						<label for="doc-select-2">选择工厂：</label>
						<select multiple id="select" class="" onchange="sel()" required>
						</select>
					</div>

					<div class="am-form-group">
						<label for="username">用户名：</label>
						<input type="text" id="username" name="username" placeholder="至少3个字符英文加数字" required onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"  readonly="readonly" / >
					</div>

					<div class="am-form-group">
						<div class="am-form-group">
							<label for="phone">手机号：</label>
							<input type="text" id="phone" name="phone" class="" placeholder="输入手机号" required/>
						</div>
					</div>
					<a class="am-btn am-btn-secondary am-btn-block am-round" onclick="reg()">提交修改</a>
				</fieldset>
			</form>
		</div>

		<script type="text/javascript">
			$(function() {
				$('#select').selected({
					btnWidth: '100%',
					btnStyle: 'default',
					maxHeight: '350px'
				});
			});
			var checkedList = new Array();

			function sel() {
				var select = document.getElementById("select");
				var tex = $("#selecteds").text();
				var str = [];
				for(i = 0; i < select.length; i++) {
					if(select.options[i].selected) {
						str += select[i].text + ',';
						checkedList[i] = select[i].value;
					}
				}
				console.log(checkedList);
				$("#selecteds").html(str);
			}

			function reg() {
				var phone = document.getElementById('phone').value;
				var reg = /^1\d{10}$/;
				var username = document.getElementById('username').value;
				var wx_id = document.getElementById('wx_id').value;
				var select = document.getElementById("select").value;
				if(select == "") {
					swal('至少选择一家工厂一个');
				} else if(username.length < 3) {
					swal('用户名，至少三个字符');
					$("#username").focus();
				} else if(!reg.test(phone)) {
					swal("手机号码输入有误");
					$("#phone").focus();
				} else {
					$.getJSON("json/locat.json", function(data) {
						var locat = data["url"];
						var originalID = data["originalID"];
						$.ajax({
							url: locat+"/appClient/updateUserInfo",
							type: "post",
							data: {
								'factory_IDs': checkedList,
								'username': username,
								'phone': phone,
								'wx_id': wx_id
							},
							dataType: "json",
							success: function(data) {
								if(data["msg"] == 'success') {
									alert("修改信息成功。");
								} else {
									alert("error");
								}
							},
							error: function() {
								swal('服务异常！');
							}
						});

					});

				}
			}
		</script>
<div data-am-widget="navbar" class="am-navbar am-cf am-navbar-default " id="">
		<ul class="am-navbar-nav am-cf am-avg-sm-3 am-avg-lg-3">
			<li>
				<a href="index.html">
					<span class="am-icon-home"></span>
					<span class="am-navbar-label">首页</span>
				</a>
			</li>
			<li>
				<a href="gsjj.html">
					<span class="am-icon-qrcode"></span>
					<span class="am-navbar-label">公司简介</span>
				</a>
			</li>
			<li>
				<a href="hzgc.html">
					<span class="am-icon-arrows"></span>
					<span class="am-navbar-label">销售产品</span>
				</a>
			</li>
			<li>
				<a href="lsdd.html">
					<span class="am-icon-eye"></span>
					<span class="am-navbar-label">查看货单</span>
				</a>
			</li>
			<li>
				<a href="user.html">
					<span class="am-icon-user"></span>
					<span class="am-navbar-label">个人中心</span>
				</a>
			</li>

		</ul>
	</div>

	<!--6-->
	<div data-am-widget="gotop" class="am-gotop am-gotop-fixed">
		<a href="#top" title=""> <img class="am-gotop-icon-custom" src="img/s.png" />
		</a>
	</div>
	</body>

</html>